<template>
	<!-- 不安全行为台账 -->
	<view class="">
		<u-navbar title="不安全行为台账" :placeholder="true" leftIconColor="#fff" @rightClick="openPopup" titleStyle="color: #fff" bgColor="#2172FC" :autoBack="true">
			<template #right>
				<u-icon name="hourglass" color="#fff" size="25"></u-icon>
			</template>
		</u-navbar>
	</view>
	<view class="p-10">
		<template v-if="list.length > 0">
			<view class="card" v-for="(item, index) in list" :key="index" @click="goDetail(item)">
				<view class="flex m-between">
					<view class="name fw">违章级别: {{ item.vioLevelName }}</view>
					<view class="pro">发现人: {{ item.stopUserName }}</view>
				</view>
				<view class="flex m-between m-t-8">
					<view class="post">违章时间: {{ item.vioDate }}</view>
					<view class="pro">违章单位: {{ item.vioDeptName }}</view>
				</view>
				<view class="flex m-between m-t-8">
					违章地点:
					<up-text :lines="1" :text="item.riskLocationName"></up-text>
				</view>
				<view class="flex m-between m-t-8">
					<view class="post">违章人员: {{ item.vioUserName }}</view>
				</view>
			</view>
		</template>
		<u-empty v-else mode="data"></u-empty>
	</view>
	<!-- 筛选popup -->
	<my-popup :show="showPopup" :queryParams="queryParams" :formItem="formData" @close="closePopup" @reset="reset" @submit="submit"></my-popup>
	<u-back-top :scroll-top="scrollTop" top="600"></u-back-top>
</template>
<script setup>
import { reactive, computed } from 'vue';
import { getViolation } from '@/api/hidden-danger.js';
import useList from '@/hooks/useList.js';

let formData = computed(() => {
	return [
		{
			itemType: 'select',
			label: '违章级别',
			type: 'GETvioLevel',
			prop: 'vioLevel'
		},
		{
			label: '违章地点',
			itemType: 'select',
			list: checkList.value,
			prop: 'riskLocationId'
		},
		{
			label: '违章人员',
			prop: 'vioUserName'
		},
		{
			label: '发现人',
			prop: 'stopUserName'
		}
	];
});

let queryParams = reactive({
	pageNum: 1,
	pageSize: 10,
	type: 0
});
// 跳转详情
const goDetail = (item) => {
	uni.navigateTo({
		url: '/pages/professional/risk/ledger/detail?data=' + JSON.stringify(item)
	});
};
const { getListData, getCheckPonit, list, checkList, scrollTop, showPopup, openPopup, closePopup, submit } = useList({
	queryParams,
	api: {
		page: getViolation
	}
});

const init = () => {
	getListData();
	getCheckPonit();
};
init();

// 重置查询条件
const reset = () => {
	for (const item of formData.value) {
		queryParams[item.prop] = '';
	}
	queryParams.type = 0;
	getListData();
	showPopup.value = false;
};
</script>
<style lang="scss" scoped></style>
